$(function() {
	admin.communityMessage.init();
});
Namespace('admin.communityMessage', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	unclaimed:function(id) {
		var url = contextPath + '/community/message/unclaimed';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('设置状态删除成功');
				top.addTab("1",'社区大喇叭列表', contextPath+'/community/message/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	receive:function(id) {
		var url = contextPath + '/community/message/receive';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('设置状态正常成功');
				top.addTab("1",'社区大喇叭列表', contextPath+'/community/message/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	reveal:function(id) {
		var url = contextPath + '/community/message/reveal';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('设置显示成功');
				top.addTab("1",'社区大喇叭列表', contextPath+'/community/message/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	notReveal:function(id) {
		var url = contextPath + '/community/message/notReveal';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('设置取消显示成功');
				top.addTab("1",'社区大喇叭列表', contextPath+'/community/message/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	doTop: function (id) {
		var tip = "确定置顶吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/community/message/doTop';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
                    admin.communityMessage.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	undoTop: function (id) {
		var tip = "确定取消置顶吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/community/message/undoTop';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
                    admin.communityMessage.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	
	/**
	 * 取消官方
	 */
	countermand: function (id) {
        var url = contextPath + '/community/message/countermand';
		$('#datagrid').datagrid('loading');
		$.post(url, {'id': id}, function (result) {
			$('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('操作成功');
				var pageopt = $('#datagrid').datagrid('getPager').data("pagination").options;
				admin.communityMessage.query();
			} else {
				top.showInfo(result.msg);
			}
		});
	},
});